home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Documents / JAVA Programming / examples / 13 / ByteArrayOutputStreamS.java < prev    next >
Encoding:
Java Source  |  2000-09-08  |  870 b   |  30 lines

  1. import java.io.*;
  2. import java.util.*;
  3. class ByteArrayOutputStreamS {
  4. public static void main(String args[]) throws Exception {
  5. int i;
  6. ByteArrayOutputStream f0 = new ByteArrayOutputStream(12);
  7. System.out.println("Enter 10 characters and a return");
  8. while (f0.size() != 10) { 
  9. f0.write(System.in.read());
  10. }
  11. System.out.println("Buffer as a string");
  12. System.out.println(f0.toString());
  13. System.out.println ("Into array");
  14. byte b[] = f0.toByteArray();
  15. for (i=0; i < b.length; i++) {
  16. System.out.print((char) b[i]);
  17. }
  18. System.out.println();
  19. System.out. println("To an OutputStream()");
  20. OutputStream f2 = new FileOutputStream("test.txt");
  21. f0.writeTo(f2);
  22. System.out.println("Doing a reset");
  23. f0.reset();
  24. System.out.println("Enter 10 characters and a return");
  25. while (f0.size() != 10) { 
  26. f0.write(System.in.read());
  27. System.out.println("Done.");
  28. } }
  29.